Ext.define('Era.controller.Main',{
    extend: 'Ext.app.Controller',
    
    statics: {
        
        loadComponents: function() {
            
            // load the bar and menu
            this.mainContainer  = Ext.create('Era.view.MainContainer');
            this.menuWindow     = Ext.create('Era.view.MenuWindow');
           
           // initialize stores
           this.stores = [];
           this.stores['events'] = Ext.create('Era.store.Events');
           this.stores['history'] = Ext.create('Era.store.History');
           
           
        },

        showMenuWindow: function() {
            this.menuWindow.menuPanel.removeAll();
            this.menuWindow.show();          
        },
        
        showMenuScreen: function(screen,openWindow) {
            
            this.menuWindow.loadScreen(screen);
            
            if (openWindow) {
                this.menuWindow.show();
            }
            
        },
        
        showPreviewWindow: function(view,record) {

            // destroy previous
            if (this.previewWindow != null && this.previewWindow != 'undefined') {
                this.previewWindow.destroy();
            }
            
            // create new
            this.previewWindow = Ext.create('Era.view.PreviewWindow',{record:record});

            //show preview
            this.previewWindow.show();
            
            // align to grid position
            if (view.getEl().getX() < 905) {
                this.previewWindow.alignTo(view.getEl(),'tl-tr',[5,0]);
            } else {
                this.previewWindow.alignTo(view.getEl(),'tr-tl',[-5,0]);
            }
        },
        
        hidePreviewWindow: function() {
            
            // exists?
            if (this.previewWindow != null || this.previewWindow != 'undefned'){
                this.previewWindow.hide();
            }
            
        },
        
        showIconWindow: function() {
            
            // destroy previous
            if (this.iconWindow != null && this.iconWindow != 'undefined') {
                this.iconWindow.destroy();
            }
            
            // create new
            this.iconWindow = Ext.create('Ext.window.Window',{
                title: 'Icons Gallery',
     
                modal: true,
                draggable: false,
                resizable: false,
                shadow: false,
                items: [
                    {
                        xtype: 'iconscreen'
                    }
                ]
            });

            //show preview
            this.iconWindow.show();
            
            
        },
        
        hideIconWindow: function() {
            if (this.iconWindow != null && this.iconWindow != 'undefined') {
                this.iconWindow.hide();
            }
        },
        
        getStore: function(id) {
            
            //return all events store
            return this.stores[id];

        }
    }
    
});